﻿using System;
using System.IO;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

// Token: 0x0200016B RID: 363
public class CharaSaveUI : MonoBehaviour
{
	// Token: 0x1700012A RID: 298
	// (get) Token: 0x06000978 RID: 2424 RVA: 0x00037F50 File Offset: 0x00036150
	private GameControl GameCtrl
	{
		get
		{
			if (this.gameCtrl == null)
			{
				this.gameCtrl = UnityEngine.Object.FindObjectOfType<GameControl>();
			}
			return this.gameCtrl;
		}
	}

	// Token: 0x06000979 RID: 2425 RVA: 0x00037F74 File Offset: 0x00036174
	private void Awake()
	{
		this.input.onEndEdit.AddListener(new UnityAction<string>(this.InputString));
		this.inputButtonSave.onClick.AddListener(new UnityAction(this.Button_SaveNew));
		this.inputButtonCancel.onClick.AddListener(new UnityAction(this.Button_Cancel));
		this.yesNoButtonSave.onClick.AddListener(new UnityAction(this.Button_SaveOverwrite));
		this.yesNoButtonCancel.onClick.AddListener(new UnityAction(this.Button_Cancel));
	}

	// Token: 0x0600097A RID: 2426 RVA: 0x00038010 File Offset: 0x00036210
	public void Save_New(Texture2D captureTex, Action<string> saveAct, Action cancelAct)
	{
		this.saveAct_new = saveAct;
		this.cancelAct = cancelAct;
		this.mode = CharaSaveUI.MODE.STRING;
		base.gameObject.SetActive(true);
		this.inputRoot.SetActive(true);
		this.yesNoRoot.SetActive(false);
		this.CardSprite(captureTex);
	}

	// Token: 0x0600097B RID: 2427 RVA: 0x00038060 File Offset: 0x00036260
	public void Save_Overwrite(Texture2D captureTex, Action saveAct, Action cancelAct)
	{
		this.saveAct_overwrite = saveAct;
		this.cancelAct = cancelAct;
		this.mode = CharaSaveUI.MODE.YESNO;
		base.gameObject.SetActive(true);
		this.inputRoot.SetActive(false);
		this.yesNoRoot.SetActive(true);
		this.CardSprite(captureTex);
	}

	// Token: 0x0600097C RID: 2428 RVA: 0x000380B0 File Offset: 0x000362B0
	private void CardSprite(Texture2D tex)
	{
		Vector2 png_Size = CardFileList.PNG_Size;
		if (tex != null)
		{
			png_Size.x = (float)tex.width;
			png_Size.y = (float)tex.height;
		}
		this.cardImage.sprite = Sprite.Create(tex, new Rect(Vector2.zero, png_Size), png_Size * 0.5f, 100f, 0U, SpriteMeshType.FullRect);
	}

	// Token: 0x0600097D RID: 2429 RVA: 0x0003811C File Offset: 0x0003631C
	private void Button_SaveNew()
	{
		if (this.saveAct_new != null)
		{
			this.saveAct_new(this.input.text);
		}
		this.GameCtrl.audioCtrl.Play2DSE(this.GameCtrl.audioCtrl.systemSE_yes);
		this.Close();
	}

	// Token: 0x0600097E RID: 2430 RVA: 0x00038170 File Offset: 0x00036370
	private void Button_SaveOverwrite()
	{
		if (this.saveAct_overwrite != null)
		{
			this.saveAct_overwrite();
		}
		this.GameCtrl.audioCtrl.Play2DSE(this.GameCtrl.audioCtrl.systemSE_yes);
		this.Close();
	}

	// Token: 0x0600097F RID: 2431 RVA: 0x000381B0 File Offset: 0x000363B0
	private void Button_Cancel()
	{
		if (this.cancelAct != null)
		{
			this.cancelAct();
		}
		this.GameCtrl.audioCtrl.Play2DSE(this.GameCtrl.audioCtrl.systemSE_no);
		this.Close();
	}

	// Token: 0x06000980 RID: 2432 RVA: 0x000381F0 File Offset: 0x000363F0
	private void Close()
	{
		base.gameObject.SetActive(false);
	}

	// Token: 0x06000981 RID: 2433 RVA: 0x00038200 File Offset: 0x00036400
	private void Update()
	{
		if (this.mode == CharaSaveUI.MODE.STRING)
		{
			this.inputButtonSave.interactable = (this.input.text.Length > 0);
		}
	}

	// Token: 0x06000982 RID: 2434 RVA: 0x0003822C File Offset: 0x0003642C
	private void InputString(string str)
	{
		if (!this.invoke)
		{
			return;
		}
		this.CheckFileName();
	}

	// Token: 0x06000983 RID: 2435 RVA: 0x00038240 File Offset: 0x00036440
	private void CheckFileName()
	{
		string text = this.input.text;
		char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
		foreach (char c in invalidFileNameChars)
		{
			text = text.Replace(c.ToString(), string.Empty);
		}
		this.invoke = false;
		this.input.text = text;
		this.invoke = true;
	}

	// Token: 0x0400094E RID: 2382
	[SerializeField]
	private Image cardImage;

	// Token: 0x0400094F RID: 2383
	[SerializeField]
	private GameObject inputRoot;

	// Token: 0x04000950 RID: 2384
	[SerializeField]
	private GameObject yesNoRoot;

	// Token: 0x04000951 RID: 2385
	[SerializeField]
	private InputField input;

	// Token: 0x04000952 RID: 2386
	[SerializeField]
	private Button inputButtonSave;

	// Token: 0x04000953 RID: 2387
	[SerializeField]
	private Button inputButtonCancel;

	// Token: 0x04000954 RID: 2388
	[SerializeField]
	private Button yesNoButtonSave;

	// Token: 0x04000955 RID: 2389
	[SerializeField]
	private Button yesNoButtonCancel;

	// Token: 0x04000956 RID: 2390
	private Action<string> saveAct_new;

	// Token: 0x04000957 RID: 2391
	private Action saveAct_overwrite;

	// Token: 0x04000958 RID: 2392
	private Action cancelAct;

	// Token: 0x04000959 RID: 2393
	private GameControl gameCtrl;

	// Token: 0x0400095A RID: 2394
	private CharaSaveUI.MODE mode;

	// Token: 0x0400095B RID: 2395
	private bool invoke = true;

	// Token: 0x0200016C RID: 364
	private enum MODE
	{
		// Token: 0x0400095D RID: 2397
		STRING,
		// Token: 0x0400095E RID: 2398
		YESNO
	}
}
